package com.singzi.leetcode.N200;

import java.util.Queue;
import java.util.Stack;
import java.util.TreeMap;

public class T0155 {

}
class MinStack {
    Stack<Integer> stack;
    TreeMap<Integer, Integer> treeMap;

    public MinStack() {
        stack = new Stack<>();
        treeMap = new TreeMap<>();
    }

    public void push(int val) {
        stack.push(val);
        treeMap.put(val, treeMap.getOrDefault(val, 0)+1);

    }

    public void pop() {
        int num = stack.pop();
        treeMap.put(num, treeMap.get(num)-1);
        if(treeMap.get(num)==1) treeMap.remove(num);
//        stack.pop();

    }

    public int top() {
        return stack.peek();
    }

    public int getMin() {
        return treeMap.firstKey();
    }
}